<?php
/* --------------------------------------------------------------
   whats_new.php 2012-02-20 gm
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2012 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------


   based on: 
   (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
   (c) 2002-2003 osCommerce(whats_new.php,v 1.31 2003/02/10); www.oscommerce.com 
   (c) 2003	 nextcommerce (whats_new.php,v 1.12 2003/08/21); www.nextcommerce.org
   (c) 2003 XT-Commerce - community made shopping http://www.xt-commerce.com ($Id: whats_new.php 1292 2005-10-07 16:10:55Z mz $)

   Released under the GNU General Public License 
   -----------------------------------------------------------------------------------------
   Third Party contributions:
   Enable_Disable_Categories 1.3        	Autor: Mikel Williams | mikel@ladykatcostumes.com

   Released under the GNU General Public License 
   ---------------------------------------------------------------------------------------*/
$box_smarty = new smarty;
$box_smarty->assign('tpl_path', 'templates/'.CURRENT_TEMPLATE.'/');
$box_content = '';
// include needed functions
require_once (DIR_FS_INC.'xtc_random_select.inc.php');
require_once (DIR_FS_INC.'xtc_rand.inc.php');
require_once (DIR_FS_INC.'xtc_get_products_name.inc.php');

//fsk18 lock
$fsk_lock = '';
if ($_SESSION['customers_status']['customers_fsk18_display'] == '0') {
	$fsk_lock = ' and p.products_fsk18!=1';
}
if (GROUP_CHECK == 'true') {
	$group_check = " and p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
}
// BOF GM_MOD
if (MAX_DISPLAY_NEW_PRODUCTS_DAYS != '0') {
	$date_new_products = date("Y.m.d", mktime(1, 1, 1, date(m), date(d) - MAX_DISPLAY_NEW_PRODUCTS_DAYS, date(Y)));
	$days = " and p.products_date_added > '".$date_new_products."' ";
}

$t_products_sql = "select distinct
		   p.products_id,
		   pd.gm_alt_text,
		   p.products_image,
		   p.products_tax_class_id,
		   p.products_vpe,
		   p.products_vpe_status,
		   p.products_vpe_value,
		   p.products_price
		   from
			( SELECT
					p.products_id,
					p.products_image,
					p.products_tax_class_id,
					p.products_vpe,
					p.products_vpe_status,
					p.products_vpe_value,
					p.products_price,
					p.products_status,
					p.products_date_added
				FROM " .TABLE_PRODUCTS . " p
				WHERE
					p.products_status = 1
					"  .$t_days . "
					" . $t_group_check . "
					" . $t_fsk_lock . "
				ORDER BY p.products_date_added DESC
			) AS p,
		   ".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
		   " . TABLE_PRODUCTS_DESCRIPTION . " pd,
		   ".TABLE_CATEGORIES." c
		   where
		   p.products_id = pd.products_id
		   and p.products_id = p2c.products_id
		   and p.products_id !='".(int) $_GET['products_id']."'
		   and c.categories_id = p2c.categories_id
		   and c.categories_status=1 limit ".MAX_RANDOM_SELECT_NEW;

if(isset($t_result_array['version']) && version_compare(gm_get_env_info('MYSQL_VERSION'), '4.1') < 0)
{
	$t_products_sql = "select distinct
			   p.products_id,
			   pd.gm_alt_text,
			   p.products_image,
			   p.products_tax_class_id,
			   p.products_vpe,
			   p.products_vpe_status,
			   p.products_vpe_value,
			   p.products_price
			   from
			   ".TABLE_PRODUCTS." p,
			   ".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
			   " . TABLE_PRODUCTS_DESCRIPTION . " pd,
			   ".TABLE_CATEGORIES." c
			   where p.products_status=1
			   and p.products_id = pd.products_id
			   and p.products_id = p2c.products_id
			   and p.products_id !='".(int) $_GET['products_id']."'
			   and c.categories_id = p2c.categories_id
			   ".$group_check."
			   ".$fsk_lock."
			   ".$days."
			   and c.categories_status=1 order by
			   p.products_date_added desc limit ".MAX_RANDOM_SELECT_NEW;
}

if (($random_product = xtc_random_select($t_products_sql))) {

	$whats_new_price = $xtPrice->xtcGetPrice($random_product['products_id'], $format = true, 1, $random_product['products_tax_class_id'], $random_product['products_price']);
}
// EOF GM_MOD
$random_product['products_name'] = xtc_get_products_name($random_product['products_id']);

if ($random_product['products_name'] != '' || $_SESSION['style_edit_mode'] == 'edit') {

	$box_smarty->assign('box_content',$product->buildDataArray($random_product));
	$box_smarty->assign('LINK_NEW_PRODUCTS',xtc_href_link(FILENAME_PRODUCTS_NEW));
	$box_smarty->assign('language', $_SESSION['language']);
	// set cache ID
	 if (!CacheCheck()) {
		$box_smarty->caching = 0;
		$box_whats_new = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_whatsnew.html');
	} else {
		$box_smarty->caching = 1;
		$box_smarty->cache_lifetime = CACHE_LIFETIME;
		$box_smarty->cache_modified_check = CACHE_CHECK;
		$cache_id = $_SESSION['language'].$random_product['products_id'].$_SESSION['customers_status']['customers_status_name'];
		$box_whats_new = $box_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_whatsnew.html', $cache_id);
	}

	$smarty->assign('box_WHATSNEW', $box_whats_new);
	
	$gm_box_pos = $coo_template_control->get_menubox_position('whatsnew');
			
	$smarty->assign($gm_box_pos, $box_whats_new);
}
?>